<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class ArticlePost extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        switch ($this->getMethod()) {
            case 'POST':
            case 'PUT':
            case 'PATCH':
                return [
                    'title' => 'required|min:5|max:45',
                    'content' => 'required',
                    'openness' => 'required|in:public,private,password',
                    'status' => 'required|in:draft,wait_audit,published,rejection',
                    'category_id' => 'required|exists:categories,id'
                ];
            default:
                return [];

        }
    }


    /**
     * 属性名称
     * @return array
     */
    public function attributes()
    {
        return [
            'title' => '文章标题',
            'content' => '文章内容',
            'openness' => '文章公开度',
            'status' => '文章状态',
            'category_id' => '文章分类'
        ];
    }
}
